﻿using System.Collections.Generic;
using System.Data;
using dk2Database.Commands;
using dk2Repository.UnitTesting;

namespace dk2Repository.Example.DAL
{
    class SelectUserByAgeCommand : QueryEntityCommandBase<IList<User>>
    {
        public SelectUserByAgeCommand(int age)
            : base("SELECT Id, Name, Age FROM Users WHERE Age > @age")
        {
            Parameters.Add("age", age);
        }

        public override IList<User> ProcessDataReader(IDataReader rdr)
        {
            var users = new List<User>();

            while (rdr.Read())
            {
                var user = new User();

                user.Id = (int)rdr[0];
                user.Name = rdr[1].ToString();

                users.Add(user);
            }
            return users;
        }
    }


}